Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

137
Vistas
How exactly does "Object.values.filter(Boolean)" work in JavaScript?

I was reading a code saw the following line of the code and am just wondering to know how does this line of code work:

    const roles = Object.values(foundUser.roles).filter(Boolean);

If this is the User Schema:

const userSchema = new Schema({
    email: {
        type: String,
        required: true,
        unique: true
    },
    username: {
        type: String,
        // required: true,
        unique: true
    },
    password: {
        type: String,
        required: true
    },
    roles: {
        User: {
            type: Number,
            default: 2001
        },
        Editor: Number,
        Admin: Number
    },
    refreshToken: [String]
});

I can't understand what does the filter(Boolean) function do? What does Boolean as input mean? What goes to the filter() and what comes out from it?

EDIT: For example if we have a User object that has the default value of roles: {User: {type: Number, default: 2001} , Editor: undefined , Admin: undefined} what would be the value of const roles? [2001] or [User]?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda